# 元组创建
tuple1 = ()  # 空元组
tuple2 = (1, 3, "abc", True)
print(tuple1)
print(tuple2)
print(type(tuple2))
tuple3 = (1,)  # 元组中，只有一个元素的时候，加一个逗号，避免解释器误以为是int数据类型
tuple4 = tuple()  # 类型转换，把参数转换成元组形式，只能字符串——>tuple
tuple5 = tuple("134fraadefrg234")
print(tuple5)  # ('1', '3', '4', 'f', 'r', 'a', 'a', 'd', 'e', 'f', 'r', 'g', '2', '3', '4')

# list->tuple
tuple6 = tuple([1, 2, 3, 4])
# tuple->list
list1 = list(tuple5)
print(list1)
# tuple->str
str1 = str(tuple5)
print(str1)  # "('1', '3', '4', 'f', 'r', 'a', 'a', 'd', 'e', 'f', 'r', 'g', '2', '3', '4')"
print(str1[1])  # ","

print("---------------------------------------------------------------------")
# 方法
tuple7 = ("HI", "HELLO", 1, 2, 3, True, "HI")
print(tuple7.count("HI"))
print(tuple7.index("HELLO"))
# print(tuple7.index("HELLOOOO"))  #报错

print("---------------------------------------------------------------------")
# 元组遍历
for i in tuple7:
    print(i)
for i, j in enumerate(tuple7):
    print(i, j)
for i in range(len(tuple7)):
    print(i, tuple7[i])
